package cn.bjit.config;

import cn.bjit.interceptor.LoginInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器的配置
 *   是用来配置拦截器，我们的拦截器就是loginInterceptor
 *   就是配置loginInterceptor这个拦截器，拦截谁，放行谁？
 */
@Configuration
@Slf4j
public class InterceptorConfig implements WebMvcConfigurer {

     public LoginInterceptor  loginInterceptor(){
         return  new LoginInterceptor();
     }

    //添加loginInterceptor这个拦截器配置
    public void addInterceptors(InterceptorRegistry registry) {
       registry.addInterceptor(loginInterceptor()) //添加拦截器
               //拦截那些路径
               .addPathPatterns("/api/user/*/**","/api/address/*/**")
               //不拦截
               .excludePathPatterns("/api/user/*/send_code","/api/user/*/captch",
                       "/api/user/*/register","/api/user/*/login","/api/user/*/upload");
    }
}
